package com.woniuxy.ams.controller;

import com.woniuxy.ams.entity.*;
import com.woniuxy.ams.service.AppraisalTemplateSerice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 新增controller，用于对部门考核模板crud
 */
@RequestMapping("/AppraisalTemplate")
@RestController
public class AppraisalTemplateController {

    @Autowired(required = false)
    AppraisalTemplateSerice AppraisalTemplateImpl;

    //查询所有模板
    @RequestMapping("/findAllTemplate")
    public ResultEntity<List<AppraisalTemplate>> findAllTemplate(@RequestBody Dept dept) {
        List<AppraisalTemplate> templates = AppraisalTemplateImpl.findAllTemplate(dept);
        return new ResultEntity<>(200, "查询成功", templates);
    }
    //查询所有模板
    @RequestMapping("/findAllTemplateBySearch")
    public ResultEntity<List<AppraisalTemplate>> findAllTemplateBySearch(@RequestBody ExamineListFormInline examineListFormInline) {
        List<AppraisalTemplate> templates = AppraisalTemplateImpl.findAllTemplateBySearch(examineListFormInline);
        return new ResultEntity<>(200, "查询成功", templates);
    }

    //查询一条模板
    @RequestMapping("/findTemplate")
    public ResultEntity<AppraisalTemplate> findTemplate(@RequestParam int id) {

        AppraisalTemplate template = AppraisalTemplateImpl.findTemplate(id);
        return new ResultEntity<>(200, "查询成功", template);
    }


    //新增一条模板
    @RequestMapping("/insertNewTemplate")
    public ResultEntity<String> insertTemplate(@RequestBody NewTemplate newTemplate) {
        int i = AppraisalTemplateImpl.insertNewTemplate(newTemplate);
        if (i > 0) {
            return new ResultEntity<>(200, "增加成功", "数据已录入数据库");
        } else {
            return new ResultEntity<>(500, "增加失败", "数据未录入数据库");
        }
    }

    //修改模板
    @RequestMapping("/updateNewTemplate")
    public ResultEntity<String> updateTemplate(@RequestBody NewTemplate newTemplate) {

        int i = AppraisalTemplateImpl.updateNewTemplate(newTemplate);
        if (i > 0) {
            return new ResultEntity<>(200, "修改成功", "数据已录入数据库");
        } else {
            return new ResultEntity<>(500, "修改失败", "数据未录入数据库");
        }
    }

    //删除模板数据
    @RequestMapping("/deleteTemplate")
    public ResultEntity<String> deleteTemplate(@RequestBody AppraisalTemplate appraisalTemplate) {
        int i = AppraisalTemplateImpl.deleteTemplate(appraisalTemplate);
        if (i > 0) {
            return new ResultEntity<>(200, "删除成功", "数据已录入数据库");
        } else {
            return new ResultEntity<>(500, "删除失败", "数据未录入数据库");
        }
    }
}